package band.wukong.practice.javase.core.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Desc: 高级正则
 * User: sunjs
 * Date: 2010-4-24 22:02:58
 */
public class SeniorRegExp {

    public static void main(String[] args) {
        abourQualifier();
//        aboutNonCapturingGroup();
    }

    /**
     * 关于修饰符
     */
    private static void abourQualifier() {
//        Pattern p = Pattern.compile(".{3,10}[0-9]");
        Pattern p = Pattern.compile(".{3,10}?[0-9]");
//        Pattern p = Pattern.compile(".{3,10}+[0-9]");
		String s = "aaaa5bbbb6";
		Matcher m = p.matcher(s);
		if(m.find())
			p(m.start() + "-" + m.end());
		else
			p("not match!");
    }

    /**
     * 关于非捕获组
     */
    private static void aboutNonCapturingGroup() {
        Pattern p = Pattern.compile(".{3}(?=a)");
		String s = "444a66b";
		Matcher m = p.matcher(s);
		while(m.find()) {
			p(m.group());
		}
    }

    private static void p(Object o) {
        System.out.println(o);
    }
}
